home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / SCSI Samples 1.0 / SCSI Simple Sample 06⁄15 ƒ / Src / SCSISimpleSampleMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-16  |  17.1 KB  |  736 lines  |  [TEXT/KAHL]

  1. /*                                SCSISimpleSampleMain.c                            */
  2. /*
  3.  * SCSISimpleSampleMain.c
  4.  * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * This is a "simple sample" that illustrates calls to the original and the
  7.  * asynchronous SCSI Managers. In particular, it contains "definitive"
  8.  * algorithms for determining the number of SCSI devices attached to a
  9.  * Macintosh system.
  10.  */
  11. #define EXTERN
  12. #include    "SCSISimpleSample.h"
  13. #include    <Packages.h>
  14. #include    <Desk.h>
  15. #include    <OSEvents.h>
  16. #pragma segment MainCode
  17.  
  18. #ifdef __powerc
  19. /*
  20.  * Power PC does not automatically define the QuickDraw globals. This is because
  21.  * only "application" code-fragments need these globals, and this cannot be
  22.  * determined before the code fragment is constructed.
  23.  */
  24. QDGlobals            qd;        /* This is not automatically defined on PowerPC        */
  25. #endif
  26.  
  27. void                                main(void);
  28. void                                EventLoop(void);
  29. void                                DoMouseEvent(void);
  30. void                                DoContentClick(
  31.         WindowPtr                        theWindow
  32.     );
  33. void                                DoCommand(
  34.         WindowPtr                        theWindow,
  35.         long                            menuChoice
  36.     );
  37. void                                DoWindowKeyDown(
  38.         WindowPtr                        theWindow
  39.     );
  40. void                                SetupEverything(void);
  41. void                                AdjustMenus(void);
  42. void                                AdjustEditMenu(
  43.         Boolean                            isDeskAccessory
  44.     );
  45. void                                SetupMenus(void);
  46. void                                BuildWindow(void);
  47. void                                DecorateDisplay(
  48.         WindowPtr                        theWindow,
  49.         Boolean                            redraw
  50.     );
  51. void                                DrawWindow(
  52.         WindowPtr                        theWindow
  53.     );
  54. void                                DoAbout(void);
  55. void                                DoPageSetup(void);
  56. void                                HexToString(
  57.         unsigned long                    value,
  58.         short                            hexDigits,
  59.         Str255                            result
  60.     );
  61. Boolean                                HexToNum(
  62.         ConstStr255Param                hexString,
  63.         unsigned long                    *result
  64.     );
  65.         
  66. #define IsOurWindow(theWindow)    ((theWindow) == gMainWindow)
  67. /*
  68.  * This preserves the currently-chosen host bus ID in case the user switches
  69.  * between "old" and "new" SCSI Managers.
  70.  */
  71. static unsigned short                gOldHostBusID;
  72.  
  73. void
  74. main(void)
  75. {
  76.         SetupEverything();
  77.         BuildWindow();
  78.         gUpdateMenusNeeded = TRUE;
  79.         gInForeground = TRUE;
  80.         gEnableNewSCSIManager = AsyncSCSIPresent();
  81.         if (gEnableNewSCSIManager)
  82.             LOG("\pHas asynchronous SCSI Manager");
  83.         else {
  84.             LOG("\pAsynchronous SCSI Manager not present");
  85.         }
  86.         gEnableSelectWithATN = gEnableNewSCSIManager;
  87.         InitCursor();
  88.         while (gQuitNow == FALSE) {
  89.             EventLoop();
  90.         }
  91.         ExitToShell();
  92. }
  93.  
  94. /*
  95.  * BuildWindow creates a document window and stores a text log
  96.  * as its content.
  97.  */
  98. void
  99. BuildWindow()
  100. {
  101.         short                    fontSize;
  102.         short                    fontNumber;
  103.         Rect                    viewRect;
  104.         
  105.         fontSize = 10;
  106.         GetFNum("\pCourier", &fontNumber);
  107.         if (RealFont(fontNumber, fontSize) == FALSE)
  108.             fontNumber = applFont;
  109.         viewRect = qd.screenBits.bounds;
  110.         viewRect.top += (GetMBarHeight() * 2);
  111.         viewRect.bottom -= 4;
  112.         viewRect.left += 4;
  113.         viewRect.right = (width(viewRect) / 2);
  114.         gMainWindow = NewWindow(
  115.                         NULL,
  116.                         &viewRect,
  117.                         "\pSCSI Scan Bus Sample",
  118.                         TRUE,
  119.                         zoomDocProc,
  120.                         (WindowPtr) -1L,
  121.                         TRUE,                /* Has GoAway box        */
  122.                         0                    /* No refCon            */
  123.                     );
  124.         if (gMainWindow == NULL) {
  125.             SysBeep(10);
  126.             ExitToShell();
  127.         }
  128.         SetPort(gMainWindow);
  129.         viewRect = gMainWindow->portRect;
  130.         viewRect.right -= kScrollBarOffset;
  131.         viewRect.bottom -= kScrollBarOffset;
  132.         gLogListHandle = CreateLog(
  133.                     &viewRect,
  134.                     fontNumber,
  135.                     fontSize,
  136.                     kLogLines
  137.                 );
  138.         if (gLogListHandle == NULL) {
  139.             SysBeep(10);
  140.             ExitToShell();
  141.         }
  142. }
  143.  
  144. void
  145. EventLoop(void)
  146. {
  147.         long                            menuChoice;
  148.         register WindowPtr                theWindow;
  149.         GrafPtr                            savePort;
  150.         Boolean                            isActivating;
  151.         
  152.         if (gUpdateMenusNeeded) {
  153.             gUpdateMenusNeeded = FALSE;
  154.             AdjustMenus();
  155.         }
  156.         WaitNextEvent(
  157.             everyEvent,
  158.             &EVENT,
  159.             (gInForeground) ? 10L : 60L,
  160.             NULL
  161.         );
  162.         theWindow = FrontWindow();
  163.         switch (EVENT.what) {
  164.         case nullEvent:
  165.             break;
  166.         case keyDown:
  167.         case autoKey:
  168.             if ((EVENT.message & charCodeMask) == '.'
  169.              && (EVENT.modifiers & cmdKey) != 0) {
  170.                 FlushEvents(keyDown | autoKey, 0);
  171.                 gQuitNow = TRUE;
  172.             }
  173.             else if ((EVENT.modifiers & cmdKey) != 0) {
  174.                 if (EVENT.what == keyDown) {
  175.                     menuChoice = MenuKey(EVENT.message & charCodeMask);
  176.                     if (HiWord(menuChoice) != 0)
  177.                         DoCommand(theWindow, menuChoice);
  178.                     else if (IsOurWindow(theWindow)) {
  179.                         DoWindowKeyDown(theWindow);
  180.                     }
  181.                 }
  182.             }
  183.             else if (IsOurWindow(theWindow)) {
  184.                 DoWindowKeyDown(theWindow);
  185.             }
  186.             break;
  187.         case mouseDown:
  188.             DoMouseEvent();
  189.             break;
  190.         case updateEvt:
  191.             theWindow = (WindowPtr) EVENT.message;
  192.             GetPort(&savePort);
  193.             SetPort(theWindow);
  194.             BeginUpdate(theWindow);
  195.             EraseRect(&theWindow->portRect);
  196.             DrawControls(theWindow);
  197.             DrawGrowIcon(theWindow);
  198.             if (IsOurWindow(theWindow))
  199.                 DrawWindow(theWindow);
  200.             EndUpdate(theWindow);
  201.             SetPort(savePort);
  202.             break;
  203.         case activateEvt:
  204.             theWindow = (WindowPtr) EVENT.message;
  205.             isActivating = ((EVENT.modifiers & activeFlag) != 0);
  206.             goto activateEvent;
  207.             break;
  208.         case osEvt:
  209.             switch (((unsigned long) EVENT.message) >> 24) {
  210.             case mouseMovedMessage:
  211.                 break;
  212.             case suspendResumeMessage:
  213.                 isActivating = ((EVENT.message & 0x01) != 0);
  214. activateEvent:        if (isActivating) {
  215.                     /*
  216.                      * Activate this window. Activate events define theWindow
  217.                      * from the event record, while suspend/resume uses the
  218.                      * pre-set FrontWindow value.
  219.                      */
  220.                     SelectWindow(theWindow);
  221.                     (void) TEFromScrap();
  222.                 }
  223.                 if (IsOurWindow(theWindow) && gLogListHandle != NULL)
  224.                     LActivate(isActivating, gLogListHandle);
  225.                 else {
  226.                     /* Desk accessory or what? */
  227.                 }
  228.                 gInForeground = isActivating;
  229.                 gUpdateMenusNeeded = TRUE;
  230.                 break;
  231.             }
  232.             break;
  233.         }
  234. }
  235.  
  236. /*
  237.  * DoMouseEvent
  238.  * The user clicked on something. Handle application-wide processing here, or call
  239.  * a Catalog Browser function for specific action.
  240.  */
  241. void
  242. DoMouseEvent(void)
  243. {
  244.         WindowPtr        theWindow;
  245.         short            whichPart;
  246.         
  247.         whichPart = FindWindow(EVENT.where, &theWindow);
  248.         if (theWindow == NULL)
  249.             theWindow = FrontWindow();
  250.         if (whichPart == inMenuBar && IsOurWindow(theWindow) == FALSE)
  251.             theWindow = FrontWindow();
  252.         switch (whichPart) {
  253.         case inDesk:
  254.             break;
  255.         case inMenuBar:
  256.             InitCursor();
  257.             DoCommand(theWindow, MenuSelect(EVENT.where));
  258.             break;
  259.         case inDrag:
  260.             DragWindow(theWindow, EVENT.where, &qd.screenBits.bounds);
  261.             break;
  262.         case inGoAway:
  263.             if (TrackGoAway(theWindow, EVENT.where)) {
  264.                 if (IsOurWindow(theWindow)) {
  265.                     /*
  266.                      * Not quite so simple: we need to handle open files, too.
  267.                      */
  268.                     gQuitNow = TRUE;
  269.                 }
  270.             }
  271.             break;
  272.         case inZoomIn:
  273.         case inZoomOut:
  274.             if (IsOurWindow(theWindow)
  275.              && TrackBox(theWindow, EVENT.where, whichPart)) {
  276.                 DoZoomWindow(theWindow, whichPart);
  277.                 goto resizeWindow;
  278.             }
  279.             break;
  280.         case inGrow:
  281.             if (IsOurWindow(theWindow)) {
  282.                 if (DoGrowWindow(
  283.                             theWindow,
  284.                             EVENT.where,
  285.                             kMinWindowWidth,
  286.                             kMinWindowHeight
  287.                         )) {
  288. resizeWindow:        DecorateDisplay(theWindow, TRUE);
  289.                 }
  290.             }
  291.             break;
  292.         case inContent:
  293.             if (theWindow != FrontWindow())
  294.                 SelectWindow(theWindow);
  295.             else if (IsOurWindow(theWindow)) {
  296.                 DoContentClick(theWindow);
  297.             }
  298.             else {
  299.                 /* Nothing happens here        */
  300.             }
  301.             break;
  302.         default:
  303.             break;
  304.         }
  305.         /*
  306.          * Do not touch theWindow here.
  307.          */
  308. }
  309.  
  310. void
  311. DoContentClick(
  312.         WindowPtr                theWindow
  313.     )
  314. {
  315.         if (0) {                /* Touch unused variables    */
  316.             theWindow;
  317.         }
  318.         DoClickInLog(gLogListHandle, &EVENT);
  319. }
  320.  
  321. void
  322. DoWindowKeyDown(
  323.         WindowPtr                        theWindow
  324.     )
  325. {
  326.         if (0) {                /* Touch unused variables    */
  327.             theWindow;
  328.         }
  329.         /* Nothing happens here */
  330. }
  331.  
  332. void
  333. DrawWindow(
  334.         WindowPtr                        theWindow
  335.     )
  336. {
  337.         if (0) {                /* Touch unused variables    */
  338.             theWindow;
  339.         }
  340.         UpdateLog(gLogListHandle);
  341. }
  342.  
  343. void
  344. DecorateDisplay(
  345.         WindowPtr                        theWindow,
  346.         Boolean                            redraw
  347.     )
  348. {
  349.         Rect                            viewRect;
  350.         
  351.         if (0) {                /* Touch unused variables    */
  352.             redraw;
  353.         }
  354.         viewRect = theWindow->portRect;
  355.         viewRect.right -= kScrollBarOffset;
  356.         viewRect.bottom -= kScrollBarOffset;
  357.         if (gLogListHandle != NULL) {
  358.             MoveLog(gLogListHandle, viewRect.left, viewRect.top);
  359.             SizeLog(gLogListHandle, width(viewRect), height(viewRect));
  360.         }
  361. }
  362.  
  363. void
  364. DoCommand(
  365.         WindowPtr                        theWindow,
  366.         long                            menuChoice
  367.     )
  368. {
  369.         short                            menuItem;
  370.         Str255                            menuText;
  371.         GrafPtr                            savePort;
  372.         OSErr                            status;
  373.         Boolean                            useAsynchManager;
  374.  
  375.         menuItem = LoWord(menuChoice);
  376.         switch (HiWord(menuChoice)) {
  377.         case MENU_Apple:
  378.             if (menuItem == kAppleAbout)
  379.                 DoAbout();
  380.             else {
  381.                 GetItem(gAppleMenu, menuItem, menuText);
  382.                 AdjustEditMenu(TRUE);
  383.                 GetPort(&savePort);
  384.                 OpenDeskAcc(menuText);
  385.                 SetPort(savePort);
  386.                 AdjustEditMenu(IsOurWindow(theWindow) == FALSE);
  387.             }
  388.             break;
  389.         case MENU_File:
  390.             switch (menuItem) {
  391.             case kFileCreateLogFile:
  392.                 status = SaveLogFile(
  393.                             gLogListHandle,
  394.                             "\pSave Log",
  395.                             "\pSCSI Test Log",
  396.                             'ttxt'
  397.                         );
  398.                 break;
  399.             case kFileCloseLogFile:
  400.                 status = CloseLogFile(gLogListHandle);
  401.                 break;
  402.             case kFilePageSetup:
  403.                 DoPageSetup();
  404.                 break;
  405.             case kFilePrint:
  406.                 PrintLog(gLogListHandle, gPrintHandle);
  407.                 break;
  408.             case kFileDebug:
  409.                 Debugger();
  410.                 break;
  411.             case kFileQuit:
  412.                 gQuitNow = TRUE;
  413.                 break;
  414.             }
  415.             break;
  416.         case MENU_Test:
  417.             switch (menuItem) {
  418.             case kTestEnableNewManager:
  419.                 /*
  420.                  * Note that this menu option is disabled if the asynchronous
  421.                  * SCSI Manager is not present. This means that, if it is
  422.                  * not present at application start, it can't be enabled later.
  423.                  */
  424.                 gEnableNewSCSIManager = (!gEnableNewSCSIManager);
  425.                 if (gEnableNewSCSIManager)
  426.                     gCurrentDevice.bus = gOldHostBusID;
  427.                 else {
  428.                     gOldHostBusID = gCurrentDevice.bus;
  429.                     gCurrentDevice.bus = 0;
  430.                 }
  431.                 gUpdateMenusNeeded = TRUE;
  432.                 break;
  433.             case kTestEnableAllLogicalUnits:
  434.                 /*
  435.                  * The ROM SCSI Manager on the Quadra 660-AV and 840-AV has
  436.                  * a bug that will hang the machine if it tries to access
  437.                  * a non-zero logical unit. This menu option makes that error
  438.                  * harder to elicit.
  439.                  */
  440.                 gMaxLogicalUnit = (gMaxLogicalUnit == 0) ? 7 : 0;
  441.                 if (gCurrentDevice.LUN > gMaxLogicalUnit)
  442.                     gCurrentDevice.LUN = gMaxLogicalUnit;
  443.                 gUpdateMenusNeeded = TRUE;
  444.                 break;
  445.             case kTestEnableSelectWithATN:
  446.                 gEnableSelectWithATN = !gEnableSelectWithATN;
  447.                 gUpdateMenusNeeded = TRUE;
  448.                 break;
  449.             case kTestDoDisconnect:
  450.                 gDoDisconnect = !gDoDisconnect;
  451.                 gUpdateMenusNeeded = TRUE;
  452.                 break;
  453.             case kTestDontDisconnect:
  454.                 gDontDisconnect = !gDontDisconnect;
  455.                 gUpdateMenusNeeded = TRUE;
  456.                 break;
  457.             case kTestVerboseDisplay:
  458.                 gVerboseDisplay = (!gVerboseDisplay);
  459.                 gUpdateMenusNeeded = TRUE;
  460.                 break;
  461.             case kTestListSCSIDevices:
  462.                 DoListSCSIDevices();
  463.                 break;
  464.             case kTestGetDriveInfo:
  465.                 status = SCSIBusAPI(gCurrentDevice, &useAsynchManager);
  466.                 if (status != noErr)
  467.                     useAsynchManager = FALSE;
  468.                 DoGetDriveInfo(gCurrentDevice, FALSE, useAsynchManager);
  469.                 break;
  470.             case kTestUnitReady:
  471.                 DoTestUnitReady(gCurrentDevice);
  472.                 break;
  473.             case kTestReadBlockZero:
  474.                 DoReadBlockZero(gCurrentDevice);
  475.                 break;
  476.             default:
  477.                 break;
  478.             }
  479.             break;
  480.         case MENU_CurrentBus:
  481.             gCurrentDevice.bus = menuItem - 1;
  482.             gUpdateMenusNeeded = TRUE;
  483.             break;
  484.         case MENU_CurrentTarget:
  485.             gCurrentDevice.targetID = menuItem - 1;
  486.             gUpdateMenusNeeded = TRUE;
  487.             break;
  488.         case MENU_CurrentLUN:
  489.             gCurrentDevice.LUN = menuItem - 1;
  490.             gUpdateMenusNeeded = TRUE;
  491.             break;
  492.         }
  493.         HiliteMenu(0);
  494. }
  495.  
  496. void
  497. SetupEverything()
  498. {
  499.         int                    i;
  500.         
  501.         MaxApplZone();
  502.         InitGraf(&qd.thePort);
  503.         InitFonts();
  504.         InitWindows();
  505.         InitMenus();
  506.         TEInit();
  507.         InitDialogs(0);
  508.         for (i = 0; i < 8; i++)
  509.             MoreMasters();
  510.         HNoPurge((Handle) GetCursor(watchCursor));
  511.         SetCursor(*GetCursor(watchCursor));
  512.         SetupMenus();
  513. }
  514.  
  515. void
  516. SetupMenus()
  517. {
  518.         register Handle        menuBarHdl;
  519.  
  520.         /*
  521.          * We ought to do some error checking here.
  522.          */
  523.         menuBarHdl = GetNewMBar(MBAR_MenuBar);
  524.         SetMenuBar(menuBarHdl);
  525.         gAppleMenu = GetMHandle(MENU_Apple);
  526.         AddResMenu(gAppleMenu, 'DRVR');
  527.         gFileMenu = GetMHandle(MENU_File);
  528.         gEditMenu = GetMHandle(MENU_Edit);
  529.         gTestMenu = GetMHandle(MENU_Test);
  530.         gCurrentBusMenu = GetMHandle(MENU_CurrentBus);
  531.         gCurrentTargetMenu = GetMHandle(MENU_CurrentTarget);
  532.         gCurrentLUNMenu = GetMHandle(MENU_CurrentLUN);
  533.         DrawMenuBar();
  534.         gUpdateMenusNeeded = TRUE;
  535. }
  536.  
  537. void
  538. AdjustMenus(void)
  539. {
  540.         short                    i;
  541.         short                    nItems;
  542.         unsigned short            maxTarget;
  543.         unsigned short            lastHostBus;
  544.         OSErr                    status;
  545.         
  546.         EnableItem(gFileMenu, kFileQuit);
  547.         EnableItem(gFileMenu, kFileDebug);
  548.         if (IsOurWindow(FrontWindow())) {
  549.             EnableItem(gFileMenu, kFilePageSetup);
  550.             EnableItem(gFileMenu, kFilePrint);
  551.             EnableItem(gTestMenu, kTestListSCSIDevices);
  552.             EnableItem(gTestMenu, kTestGetDriveInfo);
  553.             EnableItem(gTestMenu, kTestUnitReady);
  554.             EnableItem(gTestMenu, kTestVerboseDisplay);
  555.             CheckItem(gTestMenu, kTestVerboseDisplay, gVerboseDisplay);    
  556.             EnableItem(gTestMenu, kTestEnableAllLogicalUnits);
  557.             CheckItem(gTestMenu, kTestEnableAllLogicalUnits, (gMaxLogicalUnit == 7));
  558.             if (AsyncSCSIPresent()) {
  559.                 EnableItem(gTestMenu, kTestEnableNewManager);
  560.             }
  561.             else {
  562.                 DisableItem(gTestMenu, kTestEnableNewManager);
  563.             }
  564.             if (gEnableNewSCSIManager) {
  565.                 EnableItem(gCurrentBusMenu, 0);
  566.                 EnableItem(gTestMenu, kTestEnableSelectWithATN);
  567.                 EnableItem(gTestMenu, kTestDoDisconnect);
  568.                 EnableItem(gTestMenu, kTestDontDisconnect);
  569.             }
  570.             else {
  571.                 DisableItem(gCurrentBusMenu, 0);
  572.                 DisableItem(gTestMenu, kTestEnableSelectWithATN);
  573.                 DisableItem(gTestMenu, kTestDoDisconnect);
  574.                 DisableItem(gTestMenu, kTestDontDisconnect);
  575.             }
  576.             CheckItem(gTestMenu, kTestEnableNewManager, gEnableNewSCSIManager);
  577.             CheckItem(gTestMenu, kTestEnableSelectWithATN, gEnableSelectWithATN);
  578.             CheckItem(gTestMenu, kTestDoDisconnect, gDoDisconnect);
  579.             CheckItem(gTestMenu, kTestDontDisconnect, gDontDisconnect);
  580.             EnableItem(gTestMenu, kTestEnableAllLogicalUnits);
  581.             CheckItem(gTestMenu, kTestEnableAllLogicalUnits, (gMaxLogicalUnit == 7));
  582.             /* */
  583.             status = SCSIGetMaxTargetID(gCurrentDevice, &maxTarget);
  584.             if (status != noErr)
  585.                 maxTarget = 7;
  586.             nItems = CountMItems(gCurrentTargetMenu);
  587.             for (i = 1; i <= nItems; i++) {
  588.                 if ((i - 1) <= maxTarget)
  589.                     EnableItem(gCurrentTargetMenu, i);
  590.                 else {
  591.                     DisableItem(gCurrentTargetMenu, i);
  592.                 }
  593.             }
  594.             for (i = 1; i <= nItems; i++)
  595.                 CheckItem(gCurrentTargetMenu, i, (gCurrentDevice.targetID == (i - 1)) ? TRUE : FALSE);
  596.             status = SCSIGetHighHostBusAdaptor(&lastHostBus);
  597.             nItems = CountMItems(gCurrentBusMenu);
  598.             for (i = 1; i <= nItems; i++) {
  599.                 if ((i - 1) <= lastHostBus)
  600.                     EnableItem(gCurrentBusMenu, i);
  601.                 else {
  602.                     DisableItem(gCurrentBusMenu, i);
  603.                 }
  604.             }
  605.             for (i = 1; i <= nItems; i++)
  606.                 CheckItem(gCurrentBusMenu, i, (gCurrentDevice.bus == (i - 1)) ? TRUE : FALSE);
  607.             nItems = CountMItems(gCurrentLUNMenu);
  608.             for (i = 1; i <= nItems; i++) {
  609.                 if ((i - 1) <= gMaxLogicalUnit)
  610.                     EnableItem(gCurrentLUNMenu, i);
  611.                 else {
  612.                     DisableItem(gCurrentLUNMenu, i);
  613.                 }
  614.                 CheckItem(gCurrentLUNMenu, i, (gCurrentDevice.LUN == (i - 1)) ? TRUE : FALSE);
  615.             }
  616.             /* */
  617.             if (HasLogFile(gLogListHandle)) {
  618.                 EnableItem(gFileMenu, kFileCloseLogFile);
  619.                 DisableItem(gFileMenu, kFileCreateLogFile);
  620.             }
  621.             else {
  622.                 EnableItem(gFileMenu, kFileCreateLogFile);
  623.                 DisableItem(gFileMenu, kFileCloseLogFile);
  624.             }
  625.         }
  626.         AdjustEditMenu(IsOurWindow(FrontWindow()) == FALSE);
  627. }
  628.  
  629. /*
  630.  * AdjustEditMenu
  631.  * Enable/disable Edit Menu options.
  632.  */
  633. void
  634. AdjustEditMenu(
  635.         Boolean                isDeskAcc
  636.     )
  637. {
  638.         if (isDeskAcc) {
  639.             EnableItem(gEditMenu, kEditUndo);
  640.             EnableItem(gEditMenu, kEditCut);
  641.             EnableItem(gEditMenu, kEditCopy);
  642.             EnableItem(gEditMenu, kEditPaste);
  643.             EnableItem(gEditMenu, kEditClear);
  644.         }
  645.         else {
  646.             DisableItem(gEditMenu, kEditUndo);
  647.             DisableItem(gEditMenu, kEditCut);
  648.             DisableItem(gEditMenu, kEditCopy);
  649.             DisableItem(gEditMenu, kEditPaste);
  650.             DisableItem(gEditMenu, kEditClear);
  651.         }
  652. }
  653.  
  654. void
  655. DoAbout()
  656. {
  657.         GrafPtr                            savePort;
  658.         DialogPtr                        dialog;
  659.         short                            item;
  660.         
  661.         GetPort(&savePort);
  662.         dialog = GetNewDialog(DLOG_About, NULL, (WindowPtr) -1L);
  663.         ShowWindow(dialog);
  664.         SetPort(dialog);
  665.         ModalDialog(NULL, &item);
  666.         DisposDialog(dialog);
  667.         SetPort(savePort);
  668. }
  669.  
  670. void
  671. HexToString(
  672.         unsigned long                    value,
  673.         short                            hexDigits,
  674.         Str255                            result
  675.     )
  676. {
  677.         register unsigned short            digit;
  678.         register char                    *text;
  679.         
  680.         text = (char *) result;
  681.         text[0] = hexDigits;
  682.         for (; hexDigits > 0; --hexDigits) {
  683.             digit = value & 0xF;
  684.             if (digit >= 10)
  685.                 text[hexDigits] = digit - 10 + 'a';
  686.             else {
  687.                 text[hexDigits] = digit + '0';
  688.             }
  689.             value >>= 4;
  690.         }
  691. }
  692.  
  693. Boolean
  694. HexToNum(
  695.         ConstStr255Param                hexString,
  696.         unsigned long                    *result
  697.     )
  698. {
  699.         register short                    i;
  700.         register unsigned short            digit;
  701.         
  702.         *result = 0;
  703.         for (i = 1; i <= hexString[0]; i++) {
  704.             digit = hexString[i];
  705.             if (digit >= '0' && digit <= '9')
  706.                 digit -= '0';
  707.             else if (digit >= 'a' && digit <= 'f')
  708.                 digit = digit - 'a' + 10;
  709.             else if (digit >= 'A' && digit <= 'F')
  710.                 digit = digit - 'A' + 10;
  711.             else {
  712.                 return (FALSE);
  713.             }
  714.             *result <<= 4;
  715.             *result |= digit;
  716.         }
  717.         return (TRUE);
  718. }
  719.  
  720. void
  721. DoPageSetup(void)
  722. {
  723.         PrOpen();
  724.         if (PrError() == noErr) {
  725.             if (gPrintHandle == NULL) {
  726.                 gPrintHandle = (THPrint) NewHandle(sizeof (TPrint));
  727.                 if (gPrintHandle != NULL)
  728.                     PrintDefault(gPrintHandle);
  729.             }
  730.             if (gPrintHandle != NULL)
  731.                 (void) PrStlDialog(gPrintHandle);
  732.             PrClose();
  733.         }
  734. }
  735.  
  736.